<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('整机服务订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input id="orderState" name="orderState" value="0" type="hidden">
                    <div class="select-list">
                        <ul>
                            <!--<li>
                                <label>用户id：</label>
                                <input type="text" name="userId"/>
                            </li>-->
                            <li>
                                <label>联系人：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="userPhone"/>
                            </li>
                            <li>
                                <label>详细地址：</label>
                                <input type="text" name="userAddress"/>
                            </li>
                            <li>
                                <label>服务类型：</label>
                                <input type="text" name="serviceTypeId"/>
                            </li>
                            <li>
                                <label>购买日期：</label>
                                <input type="text" class="time-input" placeholder="请选择购买日期" name="buyTime"/>
                            </li>
                            <li>
                                <label>产品条码：</label>
                                <input type="text" name="electricCode"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:electricOrder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:electricOrder:remove')}]];
        var serviceTypeIdDatas = [[${@dict.getType('electric_type')}]];
        var orderStateDatas = [[${@dict.getType('electric_state')}]];
        var prefix = ctx + "zsyh/electricOrder";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                modalName: "整机服务订单",
                columns: [{
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                        var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                        return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'id',
                    title: 'id',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'userName',
                    align: 'center',
                    title: '联系人'
                },
                {
                    field: 'userPhone',
                    align: 'center',
                    title: '联系电话'
                },
                {
                    field: 'userAddress',
                    align: 'center',
                    title: '详细地址'
                },
                {
                    field: 'serviceTypeId',
                    align: 'center',
                    title: '服务类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(serviceTypeIdDatas, value);
                    }
                },
                {
                    field: 'orderState',
                    align: 'center',
                    title: '预约单状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderStateDatas, value);
                    }
                },
                {
                    field: 'buyTime',
                    align: 'center',
                    title: '购买日期'
                },
                {
                    field: 'buyTicket',
                    align: 'center',
                    title: '购买票据',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'electricCode',
                    align: 'center',
                    title: '产品条码'
                },
                    {
                        field: 'createTime',
                        align: 'center',
                        title: '下单时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewDetail(\'' + row.id + '\')"><i class="fa fa-search"></i>查看详情</a> ');
                        /*actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        if(row.orderState == '0'){
                            actions.push('<a class="btn btn-primary btn-xs ' + removeFlag + '" style="margin-left: 3px;" href="javascript:void(0)" onclick="cancelOrder(\'' + row.id + '\')"><i class="fa fa-mail-reply"></i>取消订单</a>');
                        }
                        actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" style="margin-left: 3px;" href="javascript:void(0)" onclick="addRemark(\'' + row.id + '\')"><i class="fa fa-edit"></i>添加备注</a>');
                        if(row.orderState == '0' || row.orderState == '1'){
                            actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" style="margin-left: 3px;background: mediumpurple;border-color: mediumpurple" href="javascript:void(0)" onclick="endOrder(\'' + row.id + '\')"><i class="fa fa-check"></i>完成订单</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function viewDetail(id) {
            layer.open({
                type: 2,
                area: ['1200px', ($(window).height() - 50) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看详情",
                content: prefix + "/edit/"+id,
                btnClose: 1,
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function cancelOrder(id) {
            $.modal.confirm("确认要取消订单吗？", function() {
                $.operate.post(prefix + "/cancelElectricOrder", { "id":id});
            })
        }

        function addRemark(id) {
            var url = prefix + '/addRemark/'+id;
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', '350px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "添加备注信息",
                content: url,
                /*closeBtn: 1,*/
                btn: ['确定', '取消'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function endOrder(id) {
            var url = prefix + '/endOrder/'+id;
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', '600px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "完成订单",
                content: url,
                /*closeBtn: 1,*/
                btn: ['确定', '取消'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

    </script>
</body>
</html>